import request from '@/config/axios'

// 终端设备 VO
export interface TerminalDeviceVO {
  id: number // ID
  deviceId: string // 设备ID
  deviceName: string // 设备名称
  deviceState: number // 设备状态
  monitorDeviceId: number // 监测设备
  deviceGroupId: number // 设备分组
  audioUrl: string // 音频流URL
  remark: string // 备注
  tenantId: number //租户ID
}

// 终端设备 API
export const TerminalDeviceApi = {
  // 查询终端设备分页
  getTerminalDevicePage: async (params: any) => {
    return await request.get({ url: `/vmiot/terminal-device/page`, params })
  },

  // 查询所有租户终端设备分页
  getAllTenantTerminalDevicePage: async (params: any) => {
    return await request.get({ url: `/vmiot/terminal-device/getAllTenantTerminalDevicePage`, params })
  },

  // 查询终端设备详情
  getTerminalDevice: async (id: number) => {
    return await request.get({ url: `/vmiot/terminal-device/get?id=` + id })
  },

  // 终端设备按状态分组统计数量
  getCountGroupByDeviceState: async (tenantId: number) => {
    return await request.get({ url: `/vmiot/terminal-device/getCountGroupByDeviceState?tenantId=` + tenantId })
  },

  // 同步物理传感器
  syncPhysicalSensor: async (id: number) => {
    return await request.get({ url: `/vmiot/terminal-device/syncPhysicalSensor?id=` + id })
  },

  // 新增终端设备
  createTerminalDevice: async (data: TerminalDeviceVO) => {
    return await request.post({ url: `/vmiot/terminal-device/create`, data })
  },

  // 修改终端设备
  updateTerminalDevice: async (data: TerminalDeviceVO) => {
    return await request.put({ url: `/vmiot/terminal-device/update`, data })
  },

  // 分配租户
  changeTenant: async (data) => {
    return await request.put({ url: `/vmiot/terminal-device/changeTenant`, data })
  },

  // 删除终端设备
  deleteTerminalDevice: async (id: number) => {
    return await request.delete({ url: `/vmiot/terminal-device/delete?id=` + id })
  },

  // 导出终端设备 Excel
  exportTerminalDevice: async (params) => {
    return await request.download({ url: `/vmiot/terminal-device/export-excel`, params })
  }
}
